﻿using F2B.Orchard.Schedule.Services;
using Orchard.Autoroute.Services;
using Orchard.DisplayManagement;
using Orchard.Environment.Extensions;
using Orchard.Localization;
using Orchard.Projections.Descriptors.Layout;
using Orchard.Projections.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace F2B.Orchard.Schedule.Providers.Layouts
{
    [OrchardFeature("F2B.Orchard.CalendarLayout")]
    public class UpcomingLayout: ILayoutProvider
    {
        public Localizer T { get; set; }
        protected dynamic Shape { get; set; }
        
        public UpcomingLayout(IShapeFactory shapeFactory)
        {
            Shape = shapeFactory;
            T = NullLocalizer.Instance;            
        }

        public void Describe(DescribeLayoutContext describe)
        {
            describe.For("Html", T("Html"), T("Html Layouts"))
                .Element("UpcomingEvents", T("Upcoming Events"), T("Renders content items with schedule part as list"),
                DisplayLayout,
                RenderLayout,
                "UpcomingEventsLayout");
        }

        public LocalizedString DisplayLayout(LayoutContext context)
        {
            return T("Upcoming Events");
        }

        public dynamic RenderLayout(LayoutContext context, IEnumerable<LayoutComponentResult> layoutComponentResults)
        {
            var queryId = context.LayoutRecord.QueryPartRecord.Id;

            return Shape.Upcoming(queryId: queryId);            
        }
    }
}